package com.shop.cereshop.commons.utils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class DateUtil {

    /**
     *  遍历日期
     * @param startTime
     * @param endTime
     * @return
     */
    public static List<String> traverseDate(String startTime,String endTime){
        List<String> list = new ArrayList<>();
        LocalDate beginTime = LocalDate.parse(startTime);
        LocalDate finishTime = LocalDate.parse(endTime);

        //当开始时间不大于结束时间，循环执行
        while (!beginTime.isAfter(finishTime)) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            String feeDate = beginTime.format(formatter);
            list.add(feeDate);
            //日期+1，继续执行
            beginTime = beginTime.plusDays(1);
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(traverseDate("2022-08-11", "2022-08-15"));
    }

}
